<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/orderset.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="../js/vue.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约订单管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约订单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">

            <el-card class="box-card">
                <div class="boxMain">
                    <template>
                        <div class="block">
                            <el-date-picker
                                    size="small"
                                    style="width: 260px;"
                                    v-model="queryDate"
                                    value-format="yyyy-MM-dd"
                                    type="daterange"
                                    @input="testClick"
                                    range-separator="至"
                                    start-placeholder="开始日期"
                                    end-placeholder="结束日期">
                            </el-date-picker>
                        </div>
                    </template>
                    <template>
                        <el-select
                                style="width: 150px;"
                                size="small"
                                v-model="pagination.queryString.orderType"
                                style="margin-left: 5px;"
                                placeholder="预约类型">
                            <el-option
                                    v-for="t in selectType"
                                    :key="t.value"
                                    :label="t.label"
                                    :value="t.value">
                            </el-option>
                        </el-select>

                        <el-select
                                style="width: 150px;"
                                size="small"
                                v-model="pagination.queryString.orderStatus"
                                collapse-tags
                                style="margin-left: 5px;"
                                placeholder="预约状态">
                            <el-option
                                    v-for="item in selectStatus"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                        <el-input
                                size="small"
                                style="width: 180px;"
                                placeholder="会员姓名/手机号"
                                v-model="pagination.queryString.nameOrPhone"
                                style="width: 200px;"
                                class="filter-item"
                                @keyup.enter.native="handleFilter"
                                clearable>
                        </el-input>
                    </template>
                    <el-button size="small" @click="handleCurrentChange(1)" class="dalfBut">查询</el-button>
                    <el-button size="small" type="primary" class="butT" @click="handleOrder()">预约</el-button>
                    <el-button size="small" type="primary" class="butT" @click="handleClear()">清除</el-button>
                    <el-button size="small" type="primary" class="butT" @click="handleRefresh(1)">刷新</el-button>
                </div>
            </el-card>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column width="50px" type="index" align="center" label="序号"></el-table-column>
                <el-table-column width="80px" prop="name" label="会员姓名" align="center"></el-table-column>
                <el-table-column width="140px" prop="phoneNumber" label="电话号码" align="center"></el-table-column>
                <el-table-column width="90px" prop="orderDate" label="预约日期" align="center" :formatter="dateFormat"></el-table-column>
                <el-table-column width="100px" prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column width="100px" label="预约状态" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.orderStatus}}</span>
                        <el-switch
                                v-model="scope.row.orderStatus"
                                active-value="未到诊"
                                inactive-value="已到诊"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                @change="changeSwitch(scope.row)">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column width="230px" prop="setmealName" label="套餐名称" align="center"></el-table-column>
                <el-table-column label="操作" width="200px" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
                <el-table-column label="建议" width="100px" align="center">
                    <template slot-scope="scope">
                        <el-button
                                v-if="scope.row.orderStatus=='已到诊'"
                                size="mini" type="warning"
                                @click="handleAdvice(scope.row)"
                                :disabled="scope.row.interventionId==null? false : true ">
                            {{scope.row.interventionId==null?'医生建议':'已建议'}}
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <!-- 预约标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible" width="700px">
                    <template>
                        <el-tabs v-model="activeName" :rules="rules" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="80px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="手机号码" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"
                                                          placeholder="请输入手机号"
                                                          @click="inputTelephone()"
                                                          size="medium" clearable/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约日期" prop="orderDate">
                                                <el-date-picker
                                                        size="medium"
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        value-format="yyyy-MM-dd"
                                                        :picker-options="pickerOptions"
                                                        clearable
                                                        placeholder="请选择预约日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="会员姓名">
                                                <el-input v-model="formData.name" size="medium" clearable/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="11">
                                            <el-form-item label="预约类型">
                                                <el-input
                                                        size="medium"
                                                        placeholder="手机预约"
                                                        v-model="formData.orderType"
                                                        :disabled="true">
                                                </el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="23">
                                            <el-form-item label="身份证号">
                                                <el-input v-model="formData.idCard"
                                                          size="medium"
                                                          @blur="inputIdCard(formData.idCard)"
                                                          clearable
                                                />
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="11">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex" clearable>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期">
                                                <!--日期控件-->
                                                <template>
                                                    <div class="block">
                                                        <el-date-picker
                                                                v-model="formData.birthday"
                                                                type="date"
                                                                value-format="yyyy-MM-dd"
                                                                placeholder="选择日期"
                                                                :picker-options="pickerOptionsBefore"
                                                                clearable
                                                                style="width: 100%">
                                                        </el-date-picker>
                                                    </div>
                                                </template>
                                            </el-form-item>
                                        </el-col>

                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td width="5%" align="center">
                                                <input :id="c.id" v-model="setmealId" type="checkbox"
                                                       @change="changeSetmealId(c.id)"
                                                       :value="c.id">
                                            </td>
                                            <td width="10%" align="center"><label :for="c.id">{{c.code}}</label></td>
                                            <td width="25%"><label :for="c.id">{{c.name}}</label></td>
                                            <td width="55%"><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑预约 -->
            <div class="add-form">
                <el-dialog title="编辑预约" :visible.sync="dialogFormVisible4Edit" width="700px">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="80px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="手机号码" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"
                                                          placeholder="请输入手机号"
                                                          @click="inputTelephone()"
                                                          size="medium"
                                                          clearable/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约日期" prop="orderDate">
                                                <el-date-picker
                                                        size="medium"
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        value-format="yyyy-MM-dd"
                                                        clearable
                                                        :picker-options="pickerOptions"
                                                        placeholder="请选择预约日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="会员姓名">
                                                <el-input v-model="formData.name" size="medium" clearable/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="11">
                                            <el-form-item label="预约类型">
                                                <el-select
                                                        style="width: 150px;"
                                                        size="small"
                                                        v-model="formData.orderType"
                                                        style="margin-left: 5px;"
                                                        placeholder="预约类型">
                                                    <el-option
                                                            v-for="t in selectType"
                                                            :key="t.value"
                                                            :label="t.label"
                                                            :value="t.value">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="23">
                                            <el-form-item label="身份证号">
                                                <el-input v-model="formData.idCard"
                                                          @blur="inputIdCard(formData.idCard)"
                                                          size="medium"
                                                          clearable/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="11">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex" clearable>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期">
                                                <!--日期控件-->
                                                <template>
                                                    <div class="block">
                                                        <el-date-picker
                                                                v-model="formData.birthday"
                                                                type="date"
                                                                value-format="yyyy-MM-dd"
                                                                placeholder="选择日期"
                                                                :picker-options="pickerOptionsBefore"
                                                                clearable
                                                                style="width: 100%">
                                                        </el-date-picker>
                                                    </div>
                                                </template>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td width="5%" align="center">
                                                <input :id="c.id" v-model="setmealId" type="checkbox"
                                                       @change="changeSetmealId(c.id)"
                                                       :value="c.id">
                                            </td>
                                            <td width="10%" align="center"><label :for="c.id">{{c.code}}</label></td>
                                            <td width="25%"><label :for="c.id">{{c.name}}</label></td>
                                            <td width="55%"><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 医生建议弹层 -->
            <div class="add-form">
                <el-dialog title="医生建议" :visible.sync="adviceVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本建议" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="写个建议吧">
                                                <el-input v-model="formData.doctorAdvice" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="推荐膳食" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>名称</th>
                                            <th>介绍</th>
                                            <th>食用尺寸</th>
                                            <th>适用年龄</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in foodData">
                                            <td>
                                                <input :id="c.id" v-model="foodIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                            <td><label :for="c.id">{{c.size}}</label></td>
                                            <td><label :for="c.id">{{c.age}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                            <el-tab-pane label="推荐运动" name="thirdly">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>助记码</th>
                                            <th>运动</th>
                                            <th>运动次数</th>
                                            <th>运动时间</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in sportData">
                                            <td>
                                                <input :id="c.id" v-model="sportIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.size}}</label></td>
                                            <td><label :for="c.id">{{c.runtime}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="adviceVisible = false">取消</el-button>
                        <el-button type="primary" @click="advise()">确定</el-button>
                    </div>
                </el-dialog>
            </div>


        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">

<script src="../js/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../js/jquery.min.js"></script>
<script src="../plugins/healthmobile.js"></script>
<script>

    var vue = new Vue({
        el: '#app',

        data: {
            setmealId1: '',
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryDate: [

                ],//日期范围
                queryString: {
                    startDate: null,  //开始日期
                    endDate: null,  //结束日期
                    orderType: null,  //预约类型
                    orderStatus: null,  //预约状态
                    nameOrPhone: null,  //会员姓名或手机号
                },
            },
            activeName: 'first',//添加/编辑窗口Tab标签名称
            dataList: [],//列表数据
            formData: {
                idCard: '',
                orderType: '',
            },//表单数据
            tableData: [],//新增和编辑表单中对应的套餐表数据
            setmealId: [],//新增和编辑表单中套餐选项，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                phoneNumber: [{required: true, message: '手机号码为必填项', trigger: 'blur'}],
                orderDate: [{required: true, message: '预约日期为必填项', trigger: 'blur'}]
            },
            setmeal: [],//套餐下拉列表
            selectType: [{value: '微信预约'}, {value: '手机预约'}],
            selectStatus: [{value: '未到诊'}, {value: '已到诊'}],
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now();
                }
            },
            pickerOptionsBefore:{
                disabledDate(time) {
                    return time.getTime() > Date.now()- 8.64e7;
                }
            },

            adviceVisible: false,//控制医生建议窗口显示/隐藏
            foodData: [],//医生建议表单中对应的膳食列表数据
            sportData: [],//医生建议表单中对应的运动列表数据
            foodIds: [],//医生建议中食物对应的复选框，基于双向绑定可以进行回显和数据提交
            sportIds: [],//医生建议中运动对应的复选框，基于双向绑定可以进行回显和数据提交

        },

        created() {
            this.findPage();
        },
        methods: {
            testClick(e) {
                console.log(e);
                let _this =this;
                _this.pagination.queryDate = e;
                _this.$forceUpdate();
            },
            //刷新页面
            handleRefresh(currentPage){
                this.handleClear();
                //为模型数据赋值（当前页面）
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 弹出医生建议窗口
            handleAdvice(row) {
                if (row.orderStatus==='未到诊') {
                    this.$message.error("未到诊用户无法给与建议!");
                    return;
                }
                this.resetForm();
                this.foodIds = [];
                this.sportIds = [];
                this.formData.orderId = row.id;
                //弹出干预窗口
                this.adviceVisible = true;
                this.activeName = 'first';
                //发送ajax请求，根据预约订单ID查询当前对应干预，用于基本信息的回显
                /*axios.get("/orderlist/findInterventionByOrderId.do?orderId=" + row.id).then((res) => {
                    if (res.data.flag) {
                        //查询到数据
                        this.formData = res.data.data;
                    } else {
                        //查询数据失败
                        this.$message.error(res.data.message);
                    }
                });*/
                //发送ajax请求，查询所有的膳食数据，用于展示膳食列表
                axios.get("/food/findAll.do").then((res) => {
                    if (res.data.flag) {
                        //查询检查项数据成功
                        this.foodData = res.data.data;

                    } else {
                        //查询检查项数据失败
                        this.$message.error(res.data.message);
                    }
                });
                //发送ajax请求，查询所有的运动数据，用于展示运动列表
                axios.get("/sport/findAll.do").then((res) => {
                    if (res.data.flag) {
                        //查询检查项数据成功
                        this.sportData = res.data.data;
                    } else {
                        //查询检查项数据失败
                        this.$message.error(res.data.message);
                    }
                });
            },
            //医生建议添加
            advise() {
                //发送ajax请求，将表单数据提交给后台处理
                axios.post("/orderlist/addAdvice.do?foodIds=" + this.foodIds + "&sportIds=" + this.sportIds, this.formData).then((res) => {
                    //关闭编辑窗口
                    this.adviceVisible = false;
                    if (res.data.flag) {
                        //操作成功
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                    } else {
                        //操作失败
                        this.$message.error(res.data.message);
                    }
                }).finally(() => {
                    this.findPage();
                });
            },

            /*changeCheck(cid) {
                if (this.setmealId.length > 1) {
                    for (let i = 0; i < this.setmealId.length; i++) {
                        let setmealId = this.setmealId[i];
                        if (setmealId != cid) {
                            this.setmealId[i] = "";
                        }
                    }
                }
            },*/
            //清楚查询表单
            handleClear() {
                this.pagination.queryString = {};
                this.queryDate = [];
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //为模型数据赋值（当前页面）
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //分页查询
            findPage() {
                if (this.queryDate != null && this.queryDate.length > 0 ) {
                    this.pagination.queryString.startDate = this.queryDate[0];
                    this.pagination.queryString.endDate = this.queryDate[1]
                }
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString,

                };
                axios.post("/orderlist/findPage.do", param).then((res) => {
                    this.dataList = res.data.rows;
                    this.pagination.total = res.data.total;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.activeName = 'first';
                this.setmealId = [];
            },
            // 弹出添加窗口
            handleOrder() {
                this.resetForm();
                this.dialogFormVisible = true;
                this.activeName = 'first';//默认选中first对应的tab

                //发送ajax请求，查询所有的套餐数据，用于展示套餐列表
                axios.get("/setmeal/findAll.do").then((res) => {
                    if (res.data.flag) {
                        this.tableData = res.data.data;
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
            },
            //由身份证号自动获取生日及年龄
            inputIdCard(idCard) {
                //校验身份证号码格式是否正确
                if (!checkIdCard(idCard)) {
                    this.$message.error("请输入正确的证件号码");
                } else {
                    //更新生日
                    this.$set(this.formData, 'birthday', getBirthdayFromIdCard(idCard));
                }
            },
            //添加电话预约
            handleAdd() {
                this.formData.orderType = '手机预约';
                var telephone = this.formData.phoneNumber;
                var idCard = this.formData.idCard;
                //校验手机号码是否正确
                if (!checkTelephone(telephone)) {
                    this.$message.error("请输入正确的手机号码");
                } else if (!checkIdCard(idCard)) {
                    this.$message.error("请输入正确的身份证号码");
                } else if (this.setmealId.length == 0) {
                    this.$message.error("请选择体检套餐");
                }
                else if (this.setmealId.length > 1) {
                    this.$message.error("只能选择一个体检套餐");
                } else {
                    axios.post("/orderlist/add.do?setmealId=" + this.setmealId[0], this.formData).then((res) => {
                        if (res.data.flag) {
                            //操作成功
                            this.$message({
                                type: 'success',
                                message: res.data.message
                            });
                        } else {
                            //操作失败
                            this.$message.error(res.data.message);
                        }
                    }).finally(() => {
                        this.findPage();
                        this.dialogFormVisible = false;
                    })
                }
            },
            //弹出编辑窗口
            handleUpdate(row) {
                this.dialogFormVisible4Edit = true;
                this.activeName = 'first';
                //查询预约基本信息
                axios.get("/orderlist/findById.do?id=" + row.id).then((res) => {
                    if (res.data.flag) {
                        this.formData = res.data.data;
                        this.setmealId1 = res.data.data.sid;
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
                //发送ajax请求，查询所有的套餐数据，用于展示套餐列表
                axios.get("/setmeal/findAll.do").then((res) => {
                    if (res.data.flag) {
                        this.tableData = res.data.data;
                        this.setmealId[0] = this.setmealId1;
                    } else {
                        //查询套餐数据失败
                        this.$message.error(res.data.message);
                    }
                })
            },
            //修改预约信息
            handleEdit() {
                var telephone = this.formData.phoneNumber;
                var idCard = this.formData.idCard;
                //校验手机号码是否正确
                if (!checkTelephone(telephone)) {
                    this.$message.error("请输入正确的手机号码");
                } else if (!checkIdCard(idCard)) {
                    this.$message.error("请输入正确的身份证号码");
                } else {
                    axios.post("/orderlist/update.do?setmealId=" + this.setmealId[0], this.formData).then((res) => {
                        if (res.data.flag) {
                            //操作成功
                            this.$message({
                                type: 'success',
                                message: res.data.message
                            });
                        } else {
                            //操作失败
                            this.$message.error(res.data.message);
                        }
                    }).finally(() => {
                        this.findPage();
                        this.dialogFormVisible4Edit = false;
                    })
                }
            },
            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },
            //删除预约项
            handleDelete(row) {
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/orderlist/deleteById.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            this.findPage();
                        } else {
                            this.$message.error(res.data.message)
                        }
                    }).catch((r) => { //axios对象请求的catch， 网络请求不是2xx
                        this.showMessage(r);
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                })
            },
            //修改预约状态
            changeSwitch(row) {
                //触发修改动作，传入的是修改后的状态
                axios.post("/orderlist/changeStatus.do", {id: row.id, orderStatus: row.orderStatus}).then((res) => {
                    if (res.data.flag) {
                        this.$message({
                            message: res.data.message,
                            type: 'success'
                        })
                    } else {
                        this.$message.error(res.data.message);
                        //修改失败,要变回去
                        row.orderStatus = row.orderStatus==='已到诊' ? '未到诊' : '已到诊';
                    }
                })
            },
            changeSetmealId(id) {
                this.setmealId = [];
                this.setmealId[0] = id;
            },

            //时间格式化
            dateFormat(row, column) {
                // 获取单元格数据
                let data = row[column.property];
                if (data == null) {
                    return null;
                }
                let dt = new Date(data);
                return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate();
            },
        }
    });
</script>
</html>